//
//  UIImage+KY.m
//  KYKJPackDemo
//
//  Created by Jordan zhou on 2017/9/21.
//  Copyright © 2017年 ???. All rights reserved.
//

#import "UIImage+KY.h"

@implementation UIImage (KY)
+ (UIImage *)oringinalImageWithName:(NSString *)name
{
    if (iOS7) {
        return [[self imageWithName:name] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    } else {
        return [self imageWithName:name];
    }
}

+ (UIImage *)imageWithName:(NSString *)name
{
    if (iOS7) {
        NSString *newName = [name stringByAppendingString:@"_os7"];
        
        // 利用新的文件名加载图片
        UIImage *image = [self imageNamed:newName];
        // 不存在这张图片
        if (image == nil) {
            image = [self imageNamed:name];
        }
        return image;
    } else {
        return [self imageNamed:name];
    }
}

+ (UIImage *)resizedImageWithName:(NSString *)name
{
    return [self resizedImage:name leftScale:0.5 topScale:0.5];
}

+ (UIImage *)resizedImage:(NSString *)name leftScale:(CGFloat)leftScale topScale:(CGFloat)topScale
{
    UIImage *image = [self imageWithName:name];
    
    return [image stretchableImageWithLeftCapWidth:image.size.width * leftScale topCapHeight:image.size.height * topScale];
}

+ (UIImage *)base64StrToUIImage:(NSString *)imageStr
{
    NSData *imageData = [[NSData alloc] initWithBase64EncodedString:imageStr options:NSDataBase64DecodingIgnoreUnknownCharacters];
    UIImage *image = [UIImage imageWithData:imageData];
    
    return image;
}

@end
